﻿using AspectCore.DynamicProxy;
using System.Threading.Tasks;

namespace Api.Core.AOP
{
    public abstract class BaseAop : AbstractInterceptor
    {
        public abstract override Task Invoke(AspectContext context, AspectDelegate next);

        protected async Task<object> RunAndGetReturn(AspectContext context, AspectDelegate next)
        {
            await context.Invoke(next);
            return context.IsAsync()
            ? await context.UnwrapAsyncReturnValue()
            : context.ReturnValue;
        }
    }
}
